<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Rep\ModelRep;
use Illuminate\Http\Request;

class Model extends Controller
{
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new ModelRep();
    }

    public function index(){
        $obj = '{
                "default": {
                    "serial_number": {
                        "name": "流水号",
                        "show": "1"
                    },
                    "order_number": {
                        "name": "订单号",
                        "show": "1"
                    },
                    "order_date": {
                        "name": "订单日期",
                        "show": "1"
                    },
                    "delivery_date": {
                        "name": "交货日期",
                        "show": "0"
                    },
                    "account_executive_id": {
                        "name": "业务员",
                        "show": "1"
                    },
                    "product_id": {
                        "name": "产品",
                        "show": "1"
                    },
                    "model_number_id": {
                        "name": "型号",
                        "show": "1"
                    },
                    "specification_id": {
                        "name": "规格",
                        "show": "1"
                    },
                    "color_id": {
                        "name": "颜色",
                        "show": "1"
                    },
                    "direction": {
                        "name": "方向",
                        "show": "1"
                    },
                    "customer_id": {
                        "name": "客户",
                        "show": "1"
                    },
                    "receivables": {
                        "name": "应收款",
                        "show": "1"
                    },
                    "received": {
                        "name": "已收款",
                        "show": "1"
                    },
                    "remark": {
                        "name": "备注",
                        "show": "1"
                    },
                    "emergency_procedure": {
                        "name": "紧急程序",
                        "show": "1"
                    },
                    "is_replenishment": {
                        "name": "是否是补录订单",
                        "show": "1"
                    },
                    "is_stock_up": {
                        "name": "是否备货",
                        "show": "1"
                    },
                    "user_id": {
                        "name": "添加人",
                        "show": "1"
                    },
                    "status": {
                        "name": "审核状态",
                        "show": "1"
                    },
                    "info_status": {
                        "name": "基础信息审核",
                        "show": "1"
                    },
                    "material_status": {
                        "name": "物料审核",
                        "show": "1"
                    },
                    "financial_status": {
                        "name": "财务审核",
                        "show": "1"
                    },
                    "is_audit": {
                        "name": "是否审核",
                        "show": "1"
                    },
                    "production_status": {
                        "name": "生产状态",
                        "show": "1"
                    },
                    "is_del": {
                        "name": "是否删除",
                        "show": "1"
                    }
                }
            }';
        $str = serialize($obj);
        return $str;
    }

    /**
     * 获取模型列表
     * @param Request $request
     */
    public function getModelList(Request $request){
        $params = $request->all();
        $data = $this->rep->getModelListRep($params);
        if(isset($params['is_dropdown']) && !empty($params['is_dropdown'])){
            $data = $this->rep->getModelDropDownListRep($params);
        }
        return re(0,$data,'success');
    }

    /**
     * 添加模型
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addModel(Request $request){
        $params = $request->all();
        $data = $this->rep->addModelRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 添加字段
     * @param Request $request
     */
    public function addModelField(Request $request){
        $params = $request->all();
        $data = $this->rep->addModelFieldRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 获取字段列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getModelFieldList(Request $request){
        $params = $request->all();
        $data = $this->rep->getModelFieldListRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 默认字段显示设置
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateDefauleFieldShow(Request $request){
        $params = $request->all();
        $data = $this->rep->updateDefauleFieldShowRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 删除字段
     * @param Request $request
     */
    public function delModelField(Request $request){
        $params = $request->all();
        $data = $this->rep->delModelFieldRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 获取产品字段
     * @param Request $request
     */
    public function getProductFieldList(Request $request){
        $params = $request->all();
        $data = $this->rep->getProductFieldListRep($params);
        return re(0,$data,'success');
    }



}
